import jwt from 'jsonwebtoken'
import {secret} from './app'
const verify=(ctx,next)=>{
    // 登录校验
    // ctx.body='verify 离场'
    console.log(ctx.request)
    const token=ctx.request.headers['authorzation']
    console.log(token)
    if(!token){
        ctx.body={
            code:401,
            message:'请登录'
        }
    }
    try {
        const payload = jwt.verify(token,secret)
        console.log(payload,'---')
        // ctx.body = payload
        ctx.user=payload
        next()

    } catch (error) {
        ctx.body={
            code:500,
            message:'登录过期'
        }
    }
    console.log('verify 离场')
    // next()
}

export default verify;